<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改优惠券')"/>
    <th:block th:include="include :: datetimepicker-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>

</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-coupon-edit" th:object="${couponInfo}">
        <input name="id" th:field="*{id}" type="hidden">

        <div class="form-group">
            <label class="col-sm-3 control-label is-required">优惠券标题：</label>
            <div class="col-sm-8">
                <input name="title" th:field="*{title}" class="form-control" type="text" required th:disabled="*{totalGet > 0}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">适用油品：</label>
            <div class="col-sm-6">
                <select id="productId" class="form-control select2-multiple" multiple>
                    <option th:each="one:${petrolList}" th:value="${one.productId}" th:text="${one.productCategory+one.productName}" th:selected="${one.selected}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">使用门槛(满X元可用）：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input name="reachAmount" min="0" oninput="if(value<0)value=0" th:disabled="*{totalGet > 0}" th:field="*{reachAmount}" class="form-control" type="number" required>
                    <span class="input-group-addon">元</span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">优惠券类型：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('coupon_type')}">
                    <input type="radio" th:id="${dict.dictCode}" name="couponType" th:field="*{couponType}" th:disabled="*{totalGet > 0}"
                           th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group" id="type1Box">
            <label class="col-sm-3 control-label is-required">面额：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input name="faceValue" min="1" oninput="if(value<0)value=1" th:disabled="*{totalGet > 0}" th:field="*{faceValue}" placeholder="代金券面额，填写整数" class="form-control"
                           type="number">
                    <span class="input-group-addon">元</span>
                </div>
            </div>
        </div>
        <div class="form-group" id="type2Box">
            <label class="col-sm-3 control-label is-required">折扣值：</label>
            <div class="col-sm-4">
                <input name="discount" max="0.99" min="0.01" oninput="if(value>0.99 || value<0.01)value=0.01" step="0.01" th:disabled="*{totalGet > 0}" th:field="*{discount}" placeholder="如9.1折，填写0.91" class="form-control"
                       type="number">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">总发放量：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input name="totalIssuance" min="1" oninput="if(value<0)value=1" th:field="*{totalIssuance}" placeholder="每个会员限领一张"
                           class="form-control" type="number" required>
                    <span class="input-group-addon">张</span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">已领取数量：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input name="totalGet" th:field="*{totalGet}" class="form-control" type="text" disabled>
                    <span class="input-group-addon">张</span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">已使用数量：</label>
            <div class="col-sm-4">
                <div class="input-group">
                    <input name="totalUse" th:field="*{totalUse}" class="form-control" type="text" disabled>
                    <span class="input-group-addon">张</span>
                </div>
            </div>
        </div>
        <!--<div class="form-group">-->
        <!--<label class="col-sm-3 control-label">领取开始时间：</label>-->
        <!--<div class="col-sm-8">-->
        <!--<div class="input-group date">-->
        <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
        <!--<input name="getStartTime" th:value="${#dates.format(couponInfo.getStartTime, 'yyyy-MM-dd')}"-->
        <!--class="form-control" placeholder="yyyy-MM-dd" type="text">-->
        <!--</div>-->
        <!--</div>-->
        <!--</div>-->
        <!--<div class="form-group">-->
        <!--<label class="col-sm-3 control-label">领取结束时间：</label>-->
        <!--<div class="col-sm-8">-->
        <!--<div class="input-group date">-->
        <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
        <!--<input name="getEndTime" th:value="${#dates.format(couponInfo.getEndTime, 'yyyy-MM-dd')}"-->
        <!--class="form-control" placeholder="yyyy-MM-dd" type="text">-->
        <!--</div>-->
        <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">使用开始时间：</label>
            <div class="col-sm-4">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="useStartTime" th:value="${#dates.format(couponInfo.useStartTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">使用结束时间：</label>
            <div class="col-sm-4">
                <div class="input-group date">
                    <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    <input name="useEndTime" th:value="${#dates.format(couponInfo.useEndTime, 'yyyy-MM-dd')}"
                           class="form-control" placeholder="yyyy-MM-dd" type="text">
                </div>
            </div>
        </div>

        <!--<div class="form-group">-->
            <!--<label class="col-sm-3 control-label">状态：</label>-->
            <!--<div class="col-sm-8">-->
                <!--<div class="radio-box" th:each="dict : ${@dict.getType('coupon_status')}">-->
                    <!--<input type="radio" th:id="${dict.dictCode}" name="couponStatus" th:field="*{couponStatus}"-->
                           <!--th:value="${dict.dictValue}">-->
                    <!--<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>-->
                <!--</div>-->
            <!--</div>-->
        <!--</div>-->
        <div class="form-group">
            <label class="col-sm-3 control-label">是否注册赠送：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('is_enable')}">
                    <input type="radio" th:id="${dict.dictCode}" name="isAbleActivity" th:field="*{isAbleActivity}"
                           th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否可用：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('is_enable')}">
                    <input type="radio" th:id="${dict.dictCode}" name="isEnable" th:field="*{isEnable}"
                           th:value="${dict.dictValue}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-6">
                <textarea id="remark" name="remark" class="form-control">[[*{remark}]]</textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>
<th:block th:include="include :: ztree-js"/>
<script type="text/javascript">
    var prefix = ctx + "back/shopCoupon";

    var radioVal = $('input[name="couponType"]:checked').val();
    if (radioVal == "1") {
        $("#type1Box").show();
        $("#type2Box").hide();
    } else if (radioVal == "2") {
        $("#type1Box").hide();
        $("#type2Box").show();
    }

    $('input').on('ifChecked', function (event) {
        if ($(event.target).attr("name") == "couponType") {
            var radio = $(event.target).val();
            if (radio == "1") {
                $("#type1Box").show();
                $("#type2Box").hide();
            } else if (radio == "2") {
                $("#type1Box").hide();
                $("#type2Box").show();
            }
        }
    });
    // $("input[name='getStartTime']").datetimepicker({
    //     format: "yyyy-mm-dd",
    //     minView: "month",
    //     autoclose: true
    // });
    //
    // $("input[name='getEndTime']").datetimepicker({
    //     format: "yyyy-mm-dd",
    //     minView: "month",
    //     autoclose: true
    // });

    $("input[name='useStartTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='useEndTime']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            let data = $('#form-coupon-edit').serializeArray();
            var productIdArr = $.form.selectSelects("productId");
            data.push({"name": "productIdArr", "value": productIdArr});
            $.operate.save(prefix + "/edit", data,{formId:'form-coupon-edit'});
        }
    }
</script>
</body>
</html>